require("../../utils/util.js");

var t = require("../../requests/request.js"), e = getApp();

Component({
    properties: {},
    data: {
        locateCity: "",
        currentCity: "",
        autoGovernment: null,
        cityList: null,
        provinceList: null,
        governmentName: "北京，天津，上海，重庆",
        numList: null,
        dataList: null,
        toNum: "",
        showList: null,
        winHeight: null,
        modelshow: !1
    },
    methods: {
        showCity: function(t) {
            var e = this;
            wx.getSystemInfo({
                success: function(t) {
                    e.setData({
                        winHeight: t.windowHeight
                    });
                }
            }), e.loadCityData(t), e.setData({
                modelshow: !e.data.modelshow
            });
        },
        hideCity: function() {
            this.setData({
                modelshow: !this.data.modelshow
            });
        },
        refreshLocateCity: function() {
            e.getLocateCity(), this.setData({
                locateCity: e.globalData.locateCityInfo
            });
        },
        clickCity: function(t) {
            for (var e = t.currentTarget.dataset.index, a = [], i = 0; i < this.data.showList.length; i++) a[i] = !1;
            a[e] = !0, this.setData({
                showList: a
            });
        },
        scrollNum: function(t) {
            var e = t.currentTarget.dataset.num;
            this.setData({
                toNum: e
            });
        },
        scrollToTop: function() {
            this.setData({
                toNum: "title"
            });
        },
        loadCityData: function(a) {
            var i = this, n = e.globalData.locateCityInfo, s = a;
            void 0 == s && (s = n), i.setData({
                currentCity: s.name
            });
            var o = [], r = [];
            t.getCitys(function(t) {
                for (var e = [], a = [], u = [], l = 0, c = 0; c < t.length - 1; c++) {
                    var d = t[c], h = d.EngName.substr(0, 1).toUpperCase();
                    d.Initial = h;
                    var m = i.data.governmentName.indexOf(d.CityName);
                    m > -1 && 1 == d.CityLevel && o.push(d), m < 0 && 0 == d.ParentID && (r.push(d), 
                    e[h] || (a.push(h), u[l] = !1, l++, e[h] = 1));
                }
                void 0 != s.index && (u[s.index] = !0, i.setData({
                    toNum: a[s.numindex]
                })), i.setData({
                    dataList: t,
                    locateCity: n,
                    numList: a,
                    cityList: r,
                    autoGovernment: o,
                    showList: u
                });
            });
        },
        redirectEvent: function(t) {
            var e = {};
            e.id = t.currentTarget.dataset.id, e.name = t.currentTarget.dataset.name, e.index = t.currentTarget.dataset.index, 
            e.numindex = t.currentTarget.dataset.numindex;
            var a = this;
            this.triggerEvent("callback", e, a);
        }
    }
});